package com.ylp.sys.controller;

import com.ylp.common.response.PageResult;
import com.ylp.common.response.Result;
import com.ylp.sys.domain.dto.SysLogDto;
import com.ylp.sys.domain.entity.SysLog;
import com.ylp.sys.service.SysLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统日志表 前端控制器
 * </p>
 *
 * @author cc
 * @since 2024-07-30
 */
@Tag(name = "系统日志接口")
@RestController
@RequestMapping("/sysLog")
public class SysLogController {
    private final SysLogService logService;

    public SysLogController(SysLogService logService) {
        this.logService = logService;
    }

    @PostMapping("/pageList")
    @Operation(summary = "分页查询日志")
    public Result<PageResult<SysLog>> pageList(@RequestBody SysLogDto sysLogDto) {
        PageResult<SysLog> pageResult = logService.pageList(sysLogDto);
        return Result.success(pageResult);
    }

    @Operation(summary = "删除日志")
    @PostMapping("/delete")
    public Result<String> delete(@RequestBody List<Long> ids) {
        try {
            logService.deleteByIds(ids);
        } catch (Exception e) {
            return Result.error();
        }
        return Result.success();
    }

    @Operation(summary = "查看详情")
    @GetMapping("/detail")
    public Result<SysLog> detail(@RequestParam Long id) {
        SysLog sysLog = new SysLog();
        try {
            sysLog = logService.getById(id);
        } catch (Exception e) {
            return Result.error();
        }
        return Result.success(sysLog);
    }









}
